import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) {
        int count = 0;
        for(int num = 9999; num >= 1000; num-- ) {
            int qianwei = num / 1000;
            int baiwei = num / 100 % 10;
            int shiwei = num % 100 / 10;
            int gewei = num % 10;
            if (gewei + baiwei == shiwei + qianwei) {
                System.out.print(num + " ");
                count += 1;
                if (count % 5 == 0) {
                    System.out.println("");
                }
            }
        }
        System.out.println("共有"+count+"个");
    }
}
